/**
 * Copyright (c) 2008 michiyasu wada
 * http://www.seyself.com/
 * 
 * Distributed under The MIT License.
 * [http://www.opensource.org/licenses/mit-license.php]
 */

package demo.objects 
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
import jp.progression.casts.CastSprite;
import flash.events.Event;

public class MainCast extends CastSprite
{
    //--------------------------------------------------------------------------
    //  Properties
    //--------------------------------------------------------------------------
    public function get body():BodyCast
    {
        return BodyCast(getChildByName("Body"));
    }
    
    public function get header():HeaderCast
    {
        return HeaderCast(getChildByName("Header"));
    }
    
    public function get footer():FooterCast
    {
        return FooterCast(getChildByName("Footer"));
    }
    
    public var background:Sprite;
    
    //--------------------------------------------------------------------------
    //  Constructor
    //--------------------------------------------------------------------------
    public function MainCast() 
    {
        createBackground();
    }
    
    //--------------------------------------------------------------------------
    //  Override Methods
    //--------------------------------------------------------------------------
    override protected function _onCastAdded():void
    {
        stage.addEventListener( Event.RESIZE, resizeHandler );
        resizeHandler();
    }
    
    //--------------------------------------------------------------------------
    //  Event Handler Methods
    //--------------------------------------------------------------------------
    private function resizeHandler( event:Event=null ):void
    {
        x = Math.max( 0 , ( stage.getChildAt(0).width - 800 ) / 2 >> 0 );
        y = 0;
        background.height = stage.getChildAt(0).height;
    }
    
    //--------------------------------------------------------------------------
    //  Private Methods
    //--------------------------------------------------------------------------
    private function createBackground():void
    {
        background = new Sprite();
        
        var rectFill:Shape = new Shape();
        rectFill.graphics.beginFill(0xFFFFFF, 1);
        rectFill.graphics.drawRect(0, 0, 800, 600);
        rectFill.graphics.endFill();
        
        var rectBorder:Shape = new Shape();
        rectBorder.graphics.beginFill(0xE0E0E0, 1);
        rectBorder.graphics.drawRect(-1, 0, 802, 600);
        rectBorder.graphics.endFill();
        
        background.addChild( rectBorder );
        background.addChild( rectFill );
        this.addChildAt(background, 0);
    }
}

}